package org.tacademy.myrssfeeder;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class RSSListAdapter extends BaseAdapter {

	Context mContext;
	ArrayList<RSSNewsItem> mItems = new ArrayList<RSSNewsItem>();
	
	public RSSListAdapter(Context context){
		this.mContext = context;
	}
	
	public void addItem(RSSNewsItem item){
		mItems.add(item);
	}
	
	public void setListItems(List<RSSNewsItem> lt){
		mItems = (ArrayList)lt;
	}
	
	public int getCount() {
		return mItems.size();
	}

	public Object getItem(int position) {
		return mItems.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		RSSNewsItemView itemView;
		if (convertView != null)
			itemView = (RSSNewsItemView)convertView;
		else
			itemView = new RSSNewsItemView(mContext, mItems.get(position));
		
		itemView.setIcon(mItems.get(position).getmIcon());
		itemView.setText(0, mItems.get(position).getTitle());
		itemView.setText(1, mItems.get(position).getPubDate());
		itemView.setText(2, mItems.get(position).getCategory());
		itemView.setText(3, mItems.get(position).getDescription());
		
		return itemView;
	}

	public boolean areAllItemSelectable(){
		return false;
	}
	
	public boolean isSelectable(int position){
		return false;
	}
}
